package com.primb.baselibs.util;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.primb.baselibs.R;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;


/**
 * 图片加载框架
 * 分离开来以便后期更换框架
 */
public class ImageLoaderUtil {
    /**
     * 加载图片
     *
     * @param context
     * @param view
     * @param url
     * @param type    {0-int(资源文件ID),1-Uri(系统文件地址),2-String(文件资源路径和网址)}
     */
    public static void displayImage(Context context, ImageView view, Object url, int type) {
        Picasso picasso = Picasso.with(context);
        RequestCreator creator = null;
        switch (type) {
            case 0:
                creator = picasso.load((int) url);
                break;
            case 1:
                creator = picasso.load((Uri) url);
                break;
            case 2:
                creator = picasso.load((String) url);
                break;
        }
        if (creator != null) {
            creator.placeholder(R.mipmap.image_not_exist)
                    .error(R.mipmap.image_not_exist)
                    .into(view);
        }
    }
}
